<script>
	import post from '@/request.js'
	import {
		setToken,
		getToken
	} from '@/stores/useApp.js'

	export default {
		onLaunch: async function() {
			console.log('App Launched');
			getToken().then(token => {
				if (!token) {
					// #ifdef MP-WEIXIN
					console.log("WX-LOGIN");
					wx.login({
						success(res) {
							console.log(res.code);
							let promise = uni.post("/api/wechat/LoginByCode", {
								code: res.code
							});
							promise.then(msg => {
								console.log(JSON.stringify(msg));
								if (msg.success) {
									setToken(msg.token);
								}
							});
						},
						fail(err) {
							uni.showToast({
								"title": err.errMsg,
								duration: 10000
							});
						}
					});
					// #endif
					// #ifdef H5
					// Debug代码，上线前要删除
					console.log("H5 DEBUG");
					let promise = uni.post("/debug/authen/GetToken", {
						user: "mobile-test"
					});
					promise.then(msg => {
						setToken(msg.token);
					});
					// #endif
				}
			});
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style>
	/*每个页面公共css */
	.status-bar-fixed {
		height: calc(var(--status-bar-height) + 20rpx) !important;
	}
</style>